package com.zhl.media.app.mvp.model;

import android.app.Application;

import com.google.gson.Gson;
import com.jess.arms.di.scope.FragmentScope;
import com.jess.arms.integration.IRepositoryManager;
import com.jess.arms.mvp.BaseModel;

import com.jess.arms.di.scope.ActivityScope;

import javax.inject.Inject;

import com.zhl.media.app.mvp.contract.MineContract;
import com.zhl.media.app.mvp.model.api.service.AppService;
import com.zhl.media.commonsdk.base.BaseRespose;

import java.util.List;
import java.util.Map;

import io.reactivex.Observable;
import okhttp3.MediaType;
import okhttp3.RequestBody;


@FragmentScope
public class MineModel extends BaseModel implements MineContract.Model {
    @Inject
    Gson mGson;
    @Inject
    Application mApplication;

    @Inject
    public MineModel(IRepositoryManager repositoryManager) {
        super(repositoryManager);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        this.mGson = null;
        this.mApplication = null;
    }

    @Override
    public Observable<BaseRespose<Map>> getUserInfo() {
        return mRepositoryManager.obtainRetrofitService(AppService.class).getUserInfo();
    }

    @Override
    public Observable<BaseRespose<String>> saveAbnormalInfo(Map map) {
        String route = new Gson().toJson(map);
        RequestBody jsonData = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), route);
        return mRepositoryManager.obtainRetrofitService(AppService.class).saveAbnormalInfo(jsonData);
    }
}